<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
    <script type="text/javascript" src="../src/trial.js"></script>
    <script type="text/javascript">
    
		function setUp(){
			
		}
		
		function tearDown(){
			
		}

		function test_contains_methods_exists(){

			assertNotUndefined("trial.contains", trial.contains);
			assertNotNull("trial.contains", trial.contains);
			
		}
		
		function test_contains_array_one_item(){

			assertTrue(trial.contains(["three", "two", "one"], "one"));
			assertTrue(trial.contains(["three", "two", "one"], "two"));
			assertTrue(trial.contains(["three", "two", "one"], "three"));
			assertTrue(trial.doesContain(["three", "two", "one"], "one"));
			assertTrue(trial.doesContain(["three", "two", "one"], "two"));
			assertTrue(trial.doesContain(["three", "two", "one"], "three"));
			
			assertFalse(trial.contains(["three", "two", "one"], "four"));
			assertFalse(trial.contains(["three", "two", "one"], "five"));
			assertFalse(trial.contains(["three", "two", "one"], "six"));
			
			
		}
		function test_contains_array_many_items(){

			assertTrue(trial.contains(["three", "two", "one"], "one", "two", "three"));
			assertTrue(trial.contains(["three", "two", "one"], "three", "two", "one"));
			assertTrue(trial.contains(["three", "two", "one"], "two", "three", "one"));
			assertTrue(trial.doesContain(["three", "two", "one"], "one", "two", "three"));
			assertTrue(trial.doesContain(["three", "two", "one"], "three", "two", "one"));
			assertTrue(trial.doesContain(["three", "two", "one"], "two", "three", "one"));

			assertFalse(trial.contains(["three", "two", "one"], "two", "three", "four"));
			assertFalse(trial.contains(["three", "two", "one"], "zero", "one", "two"));
			
		}

		function test_contains_array_can_check_for_nulls_and_undefined(){

			assertTrue(trial.contains(["three", "two", null, "one"], "one", "two", "three", null));
			assertTrue(trial.contains(["three", "two", null, "one"], null, "one", "two", "three"));
			assertTrue(trial.contains(["three", "two", undefined, "one"], "one", "two", "three", undefined));
			assertTrue(trial.doesContain(["three", "two", null, "one"], "one", "two", "three", null));
			assertTrue(trial.doesContain(["three", "two", null, "one"], null, "one", "two", "three"));
			assertTrue(trial.doesContain(["three", "two", undefined, "one"], "one", "two", "three", undefined));

			assertFalse(trial.contains(["three", "two", undefined, "one"], "one", "two", "three", null));
			
		}
		
		function test_incorrect_usage(){

			assertTrue("Incorrect usage should throw an exception.", trial.doesThrow(function(){

				trial.contains(["three", "two", "one"]);
				
			}));
			assertTrue("Incorrect usage should throw an exception.", trial.doesThrow(function(){

				trial.contains();
				
			}));
			assertTrue("Incorrect usage should throw an exception.", trial.doesThrow(function(){

				trial.contains(null, "");
				
			}));
			assertTrue("Incorrect usage should throw an exception.", trial.doesThrow(function(){

				trial.contains(undefined, "");
				
			}));
			
		}

		function test_doesContain(){

			assertTrue("doesContain should throw an exception if item not found.", trial.doesThrow(function(){

				trial.doesContain(["three", "two", undefined, "one"], "one", "two", "three", null)
				
			}));
			
		}
		
		function test_doesContain_array(){
		
		  assertTrue(
              trial.doesContain("My name is Simon.", "Simon")
          );
          assertTrue(
              trial.doesContain("My name is Simon.", "My name")
          );
          assertTrue(
              trial.doesContain("My name is Simon.", " name is ")
          );
          assertTrue(
              trial.doesContain("My name is Simon.", "i")
          );
          assertTrue(
              trial.doesContain("My name is Simon.", "n")
          );
        
          assertFalse(
              trial.doesContain("My name is Simon.", "Mat")
          );
          assertFalse(
              trial.doesContain("My name is Simon.", "isn\"t")
          );
          assertFalse(
              trial.doesContain("My name is Simon.", "q")
          );
          assertFalse(
              trial.doesContain("My name is Simon.", "1")
          );
          
		}
		
    </script>
</head>
<body>
</body>
</html>